import { useState } from 'react';

/**
 * @useApplyStep 采购申请步骤条 hooks
 * @returns currentStep 当前步数
 * @returns changeStep 修改步骤条
 * @returns stepsItems 步骤条渲染步骤
 */
export const useApplyStep = ({ step }: { step: number }) => {
  // 控制添加采购申请步骤条
  const [currentStep, setCurrentStep] = useState(step);

  // 步骤条渲染步骤
  const stepsItems = [
    { title: '基本信息', key: 'base-info' },
    { title: '标包信息', key: 'pack-info' },
    { title: '信息确认', key: 'apply-info' },
  ];

  /**
   * @changeStep 修改步骤条
   * @param state prev 为上一步、next下一步
   */
  const changeStep = (state: string) => {
    if (state == 'prev') {
      setCurrentStep(currentStep - 1);
    } else {
      setCurrentStep(currentStep + 1);
    }
  };

  return {
    currentStep,
    changeStep,
    stepsItems,
    setCurrentStep,
  };
};
